#include <string.h>
#include <stdio.h>
#include "../head/default.h"         //define 宏定义及static变量

int f_replace_string(char *source_str,char *targ_str,char *val) {
    /*将字符串中指定子字符串用指定字符串代替，targ_str 是被替换的，val是替换的字符串*/
    char temp_sstr[RES_MAX_LEN], result[RES_MAX_LEN];
    char * p,*q;
    size_t len;
    len = 0; 
    q = p = NULL;
    memset(result,0, sizeof(result));
    memset(temp_sstr, 0, sizeof(temp_sstr));
    strcpy(temp_sstr, source_str);
    p = q = temp_sstr;
    len = strlen(targ_str);
    while(q != NULL) {
        if((q = strstr(p,targ_str)) != NULL) {
            strncat(result, p, (size_t)(q - p));
            strcat(result, val);
            strcat(result, "\0");
            q += len;
            p = q;
        } else {
            strcat(result, p);
        }
    }
    memset(source_str, 0, sizeof(source_str));
    strcpy(source_str, result);
    printf("\n");
    return 0;
}

